package com.gogowan.agroenterprise.widget.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.model.StoreModel;

/**
 * 仓库spinner adapter
 * 
 * @author tjh 2017-01-13
 *
 */
public class StoreSpinnerAdapter extends BaseAdapter {
	private Context mContext;
	private List<StoreModel> storeList;
    private Spinner spinner;
	public StoreSpinnerAdapter(Context mContext, List<StoreModel> storeList, Spinner spinner) {
		this.mContext = mContext;
		this.storeList = storeList;
		this.spinner = spinner;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return storeList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return storeList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return storeList.get(position).getStoreID();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.new_activity_store_spinner_item, null);
			viewHolder.tvLetter = (TextView) convertView
					.findViewById(R.id.store_spinner_item_ckmc_text);
			viewHolder.selectBtn = (ImageView) convertView.findViewById(R.id.store_spinner_item_ckmc_cb);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.tvLetter.setText(storeList.get(position).getStoreName());
        //设置imagebiew 的选中状态
		   if (spinner.getSelectedItemPosition() == position) {
			   viewHolder.selectBtn.setImageResource(R.drawable.invent_select);
//			   viewHolder.selectBtn.setVisibility(View.GONE);
		   } else {
        	   viewHolder.selectBtn.setImageResource(R.drawable.invent_noselect);
           }
		return convertView;
	}

	class ViewHolder {
		TextView tvLetter;
		ImageView selectBtn;
	}

}
